package com.yungu.swift.report.controller;

import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.admin.AdminReportParam;
import com.yungu.swift.report.entity.ReportOrderFeeDay;
import com.yungu.swift.report.entity.ReportRechargeDay;
import com.yungu.swift.report.service.OrderFeeDayService;
import com.yungu.swift.report.service.RechargeDayService;
import com.yungu.swift.report.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 资金日统计控制器
 *
 * @author XiuYin.Cui
 */
@RequestMapping(value = "/report/financeFlowDay")
@RestController
@Api(value = "【资金统计】", tags = "资金日统计")
public class FinanceFlowDayCtrl {

    @Autowired
    private OrderFeeDayService orderFeeDayService;
    @Autowired
    private RechargeDayService rechargeDayService;

    @PostMapping("/queryPage")
    @ApiOperation(value = "资金统计数据", httpMethod = "POST")
    public ResponseData<Map<String, Object>> queryPage(@RequestBody AdminReportParam reportParam) {
        switch (reportParam.getTypeReport()) {
            //补贴总费用
            case 3: {
                return rechargeDayService.queryPageSubsidy(reportParam);
            }
            //在线充值金额
            case 4: {
                return rechargeDayService.queryPage(reportParam);
            }
            //默认：订单金额：状态,支付方式；客单价
            default: {
                return orderFeeDayService.queryPage(reportParam);
            }
        }
    }

    @PostMapping("/export")
    @ApiOperation(value = "资金统计数据导出", httpMethod = "POST")
    public void export(@RequestBody AdminReportParam reportParam, HttpServletResponse response) throws Exception {
        switch (reportParam.getTypeReport()) {
            // 订单总金额
            case 1: {
                List list = orderFeeDayService.list(reportParam).getData();
                ExcelUtil.download(reportParam, response, list, ReportOrderFeeDay.class, "/template/order_fee_state_day_report.xlsx", "乘客实际支付金额");

            }
            // 客单价
            case 2: {
                List list = orderFeeDayService.list(reportParam).getData();
                ExcelUtil.download(reportParam, response, list, ReportOrderFeeDay.class, "/template/order_fee_per_fee_day_report.xlsx", "客单价");

            }
            //乘客实际支付金额
            case 3: {
                List list = orderFeeDayService.list(reportParam).getData();
                ExcelUtil.download(reportParam, response, list, ReportOrderFeeDay.class, "/template/order_fee_pay_way_day_report.xlsx", "乘客实际支付金额");

            }
            //补贴总费用
            case 4: {
                List list = rechargeDayService.listSubsidy(reportParam).getData();
                ExcelUtil.download(reportParam, response, list, ReportRechargeDay.class, "/template/order_fee_subsidy_day_report.xlsx", "补贴总费用");

            }
            //在线充值金额
            case 5: {
                List list = rechargeDayService.list(reportParam).getData();
                ExcelUtil.download(reportParam, response, list, ReportRechargeDay.class, "/template/order_fee_recharge_day.xlsx", "在线充值金额");

            }
            // 退款金额
            case 6: {
                List list = orderFeeDayService.list(reportParam).getData();
                ExcelUtil.download(reportParam, response, list, ReportOrderFeeDay.class, "/template/order_fee_refund_day_report.xlsx", "退款金额");

            }
            //默认：订单金额：状态
            default: {
                List list = orderFeeDayService.list(reportParam).getData();
                ExcelUtil.download(reportParam, response, list, ReportOrderFeeDay.class, "/template/order_fee_state_day_report.xlsx", "订单总金额");

            }
        }
    }

    @PostMapping("/getTotalInfo")
    @ApiOperation(value = "资金统计数据汇总", httpMethod = "POST")
    public ResponseData<ReportOrderFeeDay> getTotalInfo(@RequestBody AdminReportParam reportParam) {
        return orderFeeDayService.getTotalInfo(reportParam);
    }
}
